package com;

import com.beantechs.tsp.boot.kafka.KafkaConsumerManager;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author: 司军强
 * @Date: 16:33 2019/12/25
 * @Description:
 */
@Slf4j
public class ThreadPool {



     ExecutorService pool = new ThreadPoolExecutor(20, 20, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(2000),
                new KafkaConsumerManager.DefaultThreadFactory("GS-LOCATION"), (r, executor) -> {
            try {
                executor.getQueue().put(r);
            } catch (InterruptedException e) {
                log.error("retry put task error", e.getMessage());
                e.printStackTrace();
            }
        });



    public static  void  demo1(){
        String demo1="abc";
        for (int i = 0; i < 100; i++) {
            System.out.println("这是第demo1个提交的内容 " + i);
        }
    }
    public static  void  demo2(){
        for (int i = 0; i < 100; i++) {
            System.out.println("这是第demo2个提交的内容 " + i);
        }
    };
    public static  void  demo3(){
        for (int i = 0; i < 100; i++) {
            System.out.println("这是第demo3个提交的内容 " + i);
        }
    };

    public static  void  demo4(){
        for (int i = 0; i < 100; i++) {
            System.out.println("这是第demo4个提交的内容 " + i);
        }
    };
@Test
    public void thread(){
    pool.submit(()->{
            ThreadPool.demo1();
    });

    System.out.println("执行下面的方式");

 pool.submit(()->{
        ThreadPool.demo2();
    });
    System.out.println("执行下面的方式");
    pool.submit(()->{
        ThreadPool.demo3();
    });
    System.out.println("执行下面的方式");
    pool.submit(()->{
        ThreadPool.demo4();
    });

}

}
